import { navigateTo, showToast } from '@tarojs/taro';
import { useAuthStore } from '@/store';
import { useRouterPush } from '@/composables';
import { storeToRefs } from 'pinia';

export function toPrivacy(id = '1795811785112727553') {
  navigateTo({
    url: `/package-my/privacy/index?id=${id}`
  });
}

export function toBillList() {
  jumpToUrl(`/package-my/billlist/index`)
}
export function toGuardianList() {
  jumpToUrl(`/package-my/guardianlist/index`)
}
export function toHealthCode() {
  jumpToUrl(`/package-my/healthcode/index`)
}
export function toAddrList() {
  jumpToUrl(`/package-my/addrlist/index`)
}
export function toHomeAddrList() {
  jumpToUrl(`/package-my/homeaddrlist/index`)
}

export function toServer() {
  jumpToUrl(`/package-other/nurses/index`)
}

export function toOrder() {
  jumpToUrl(`/package-other/orders/index`)
}

export function toGoodsOrder() {
  jumpToUrl(`/package-other/orders/goods`)
}

export function toMyComment() {
  const { nurseUser, openid } = storeToRefs(useAuthStore());
  const { resetAuthStore } = useAuthStore();
  if (nurseUser.value.id && openid.value) {
    navigateTo({
      url: `/package-my/comment/index`
    });
  } else {
    showToast({
      title: '请先登录！',
      icon: 'none',
      duration: 1000
    });
    setTimeout(() => {
      const { toLogin } = useRouterPush();
      resetAuthStore();
      toLogin();
    }, 1000);
  }
}

export function toRefundList() {
  const { nurseUser, openid } = storeToRefs(useAuthStore());
  const { resetAuthStore } = useAuthStore();
  if (nurseUser.value.id && openid.value) {
    navigateTo({
      url: `/package-my/refundlist/index`
    });
  } else {
    showToast({
      title: '请先登录！',
      icon: 'none',
      duration: 1000
    });
    setTimeout(() => {
      const { toLogin } = useRouterPush();
      resetAuthStore();
      toLogin();
    }, 1000);
  }
}

export function toSpecialList(type = '0') {
  const { nurseUser, openid } = storeToRefs(useAuthStore());
  const { resetAuthStore } = useAuthStore();
  if (nurseUser.value.id && openid.value) {
    navigateTo({
      url: `/package-my/specialList/index?type=${type}`
    });
  } else {
    showToast({
      title: '请先登录！',
      icon: 'none',
      duration: 1000
    });
    setTimeout(() => {
      const { toLogin } = useRouterPush();
      resetAuthStore();
      toLogin();
    }, 1000);
  }
}

export function jumpToUrl(url: string) {
  const { nurseUser, openid } = storeToRefs(useAuthStore());
  const { resetAuthStore } = useAuthStore();
  if (nurseUser.value.id && openid.value) {
    navigateTo({
      url: url
    });
  } else {
    showToast({
      title: '请先登录！',
      icon: 'none',
      duration: 1000
    });
    setTimeout(() => {
      const { toLogin } = useRouterPush();
      resetAuthStore();
      toLogin();
    }, 1000);
  }
}

export function toInfo() {
  jumpToUrl(`/package-my/info/index`)
}
// toIdCardVerify,
// toPhoneVerify,
// toFaceVerify,
// toHealthCodeVerify
export function toIdCardVerify() {
  jumpToUrl(`/package-my/info/idcard`)
}

export function toPhoneVerify() {
  jumpToUrl(`/package-my/info/phone`)
}

export function toFaceVerify() {
  jumpToUrl(`/package-my/info/face`)
}

export function toHealthCodeVerify() {
  jumpToUrl(`/package-my/info/healthcode`)
}
